
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>2.2 Pipline · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="23-sessionpool.html" />
    
    
    <link rel="prev" href="processor.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    序言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../chapter1.html">
            
                <a href="../chapter1.html">
            
                    
                    1. 快速入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../2ji-ben-zu-jian.html">
            
                <a href="../2ji-ben-zu-jian.html">
            
                    
                    2.基本组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="processor.html">
            
                <a href="processor.html">
            
                    
                    2.1 Processor
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.2" data-path="22-pipline.html">
            
                <a href="22-pipline.html">
            
                    
                    2.2 Pipline
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="23-sessionpool.html">
            
                <a href="23-sessionpool.html">
            
                    
                    2.3 SessionPool
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../3pa-chong-kong-zhi.html">
            
                <a href="../3pa-chong-kong-zhi.html">
            
                    
                    3.爬虫控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../4chou-qu-qi.html">
            
                <a href="../4chou-qu-qi.html">
            
                    
                    4.抽取器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../4chou-qu-qi/41sipsoup.html">
            
                <a href="../4chou-qu-qi/41sipsoup.html">
            
                    
                    4.1SipSoup
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../4chou-qu-qi/42tableevaluator.html">
            
                <a href="../4chou-qu-qi/42tableevaluator.html">
            
                    
                    4.2TableEvaluator
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../5zhong-zi-guan-li-qi.html">
            
                <a href="../5zhong-zi-guan-li-qi.html">
            
                    
                    5.种子管理器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../6shi-jian-xun-huan.html">
            
                <a href="../6shi-jian-xun-huan.html">
            
                    
                    6.事件循环
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../6shi-jian-xun-huan/61-eventloopgong-zuo-ji-zhi.html">
            
                <a href="../6shi-jian-xun-huan/61-eventloopgong-zuo-ji-zhi.html">
            
                    
                    6.1 eventLoop工作机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../6shi-jian-xun-huan/62zi-dong-shi-jian.html">
            
                <a href="../6shi-jian-xun-huan/62zi-dong-shi-jian.html">
            
                    
                    6.2 自动事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../6shi-jian-xun-huan/63delayevent.html">
            
                <a href="../6shi-jian-xun-huan/63delayevent.html">
            
                    
                    6.3 延时事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../6shi-jian-xun-huan/64classScanner.html">
            
                <a href="../6shi-jian-xun-huan/64classScanner.html">
            
                    
                    6.4 classScanner
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >2.2 Pipline</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>Pipline&#x662F;&#x6293;&#x53D6;&#x7ED3;&#x679C;&#x5E8F;&#x5217;&#x5316;&#x7684;&#x7EC4;&#x4EF6;&#xFF0C;&#x7528;&#x6765;&#x5B58;&#x50A8;&#x6293;&#x53D6;&#x7ED3;&#x679C;&#x3002;&#x4ED6;&#x548C;&#x5176;&#x4ED6;&#x6846;&#x67B6;&#x91CC;&#x9762;&#x7684;Pipline&#x6CA1;&#x6709;&#x4EC0;&#x4E48;&#x533A;&#x522B;&#x3002;&#x540C;&#x6837;&#x7684;&#xFF0C;VS&#x5185;&#x7F6E;&#x7684;&#x9ED8;&#x8BA4;pipline&#x53EB;&#x505A;consolePipline&#xFF0C;&#x4F5C;&#x7528;&#x53EA;&#x662F;&#x5C06;&#x6293;&#x53D6;&#x7ED3;&#x679C;&#x6253;&#x5370;&#x5230;&#x63A7;&#x5236;&#x53F0;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ConsolePipeline</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Pipeline</span> </span>{
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">saveItem</span><span class="hljs-params">(Collection&lt;String&gt; itemJson, Seed seed)</span> </span>{
        <span class="hljs-keyword">for</span> (String str : itemJson) {
            System.out.println(str);
        }
    }
}
</code></pre>
<p>&#x53E6;&#x5916;&#x4E00;&#x4E2A;&#x5185;&#x7F6E;&#x7684;&#x53EB;&#x505A;FilePipine&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x7ED3;&#x679C;&#x5199;&#x5230;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">FilePipLine</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Pipeline</span> </span>{
    <span class="hljs-keyword">private</span> String filepath;

    <span class="hljs-keyword">private</span> PrintWriter printWriter;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FilePipLine</span><span class="hljs-params">(String filepath)</span> <span class="hljs-keyword">throws</span> FileNotFoundException </span>{
        <span class="hljs-keyword">this</span>.filepath = filepath;
        printWriter = <span class="hljs-keyword">new</span> PrintWriter(<span class="hljs-keyword">new</span> FileOutputStream(<span class="hljs-keyword">new</span> File(filepath)));
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">saveItem</span><span class="hljs-params">(Collection&lt;String&gt; itemJson, Seed seed)</span> </span>{
        <span class="hljs-keyword">for</span> (String str : itemJson) {
            printWriter.println(str);
        }
        printWriter.flush();
    }
}
</code></pre>
<p>pipline&#x63A5;&#x5165;VS&#x5F88;&#x7B80;&#x5355;</p>
<pre><code class="lang-java">VSCrawlerBuilder.create().addPipeline(<span class="hljs-keyword">new</span> FilePipLine(<span class="hljs-string">&quot;~/Desktop/&quot;</span>)).build();
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="processor.html" class="navigation navigation-prev " aria-label="Previous page: 2.1 Processor">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="23-sessionpool.html" class="navigation navigation-next " aria-label="Next page: 2.3 SessionPool">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"2.2 Pipline","level":"1.3.2","depth":2,"next":{"title":"2.3 SessionPool","level":"1.3.3","depth":2,"path":"2ji-ben-zu-jian/23-sessionpool.md","ref":"2ji-ben-zu-jian/23-sessionpool.md","articles":[]},"previous":{"title":"2.1 Processor","level":"1.3.1","depth":2,"path":"2ji-ben-zu-jian/processor.md","ref":"2ji-ben-zu-jian/processor.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"2ji-ben-zu-jian/22-pipline.md","mtime":"2017-06-24T11:51:15.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-06-25T14:04:12.299Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

